<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>2.sessionStorage</title>
  </head>
  <body>
    <h2>练习sessionStorage</h2>
    <button onclick="saveData()">存数据</button> <br><br>
    <button onclick="readData()">读数据</button> <br><br>
    <button onclick="updateData()">改数据</button> <br><br>
    <button onclick="deleteDate()">删除数据</button> <br><br>
    <button onclick="clearData()">清空数据</button>

    <script type="text/javascript" >
      function saveData(){
        sessionStorage.setItem('a','哈哈')
        sessionStorage.setItem('b',123456)
        let p = {name:'action',age:18}
        sessionStorage.setItem('person',JSON.stringify(p))
      }

      function readData(){
        let x1 = sessionStorage.getItem('a')
        let x2 = sessionStorage.getItem('b')
        let x3 = sessionStorage.getItem('person')
        console.log(x1,x2,JSON.parse(x3))
      }
      
      function updateData(){
        sessionStorage.setItem('a','啦啦啦啦啦啦啦')
      }
      
      function deleteDate(){
        sessionStorage.removeItem('a')
        sessionStorage.removeItem('b')
      }

      function clearData(){
        sessionStorage.clear()
      }
      
    </script>
  </body>
</html>